﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Com.Framework;
using Com.Framework.Data;

namespace Com.Library.DB.Store
{
	public class StoreModel
	{
		public static int Create( string strUserID, string IsActive, string strStoreName,	string strCompanyNo, string strPhone, string strPost, string strAddress, string strCityName, string IsTakeout, string strTakeout
			, string IsParking, string strParking, string strStoreSize, string strOpenDate, string strOpenTime, string strPointX, string strPointY, string strDescription, string ManagerName )
		{
			StoreCreateArguments arg = new StoreCreateArguments();
			arg.strUserID = strUserID;
			if (IsActive != null && IsActive != string.Empty) arg.IsActive = IsActive;
			if (strStoreName != null && strStoreName != string.Empty) arg.strStoreName = strStoreName;
			if (strCompanyNo != null && strCompanyNo != string.Empty) arg.strCompanyNo = strCompanyNo;
			if (strPhone != null && strPhone != string.Empty) arg.strPhone = strPhone;
			if (strPost != null && strPost != string.Empty) arg.strPost = strPost;
			if (strAddress != null && strAddress != string.Empty) arg.strAddress = strAddress;
			if (strCityName != null && strCityName != string.Empty) arg.strCityName = strCityName;
			if (IsTakeout != null && IsTakeout != string.Empty) arg.IsTakeout = IsTakeout;
			if (strTakeout != null && strTakeout != string.Empty) arg.strTakeout = strTakeout;
			if (IsParking != null && IsParking != string.Empty) arg.IsParking = IsParking;
			if (strParking != null && strParking != string.Empty) arg.strParking = strParking;
			if (strStoreSize != null && strStoreSize != string.Empty) arg.strStoreSize = strStoreSize;
			if (strOpenDate != null && strOpenDate != string.Empty) arg.strOpenDate = strOpenDate;
			if (strOpenTime != null && strOpenTime != string.Empty) arg.strOpenTime = strOpenTime;
			if (strPointX != null && strPointX != string.Empty) arg.strPointX = strPointX;
			if (strPointY != null && strPointY != string.Empty) arg.strPointY = strPointY;
			if (strDescription != null && strDescription != string.Empty) arg.strDescription = strDescription;
			if (ManagerName != null && ManagerName != string.Empty) arg.strManagerName = ManagerName;

			StoreCreate sp = new StoreCreate();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();

			int n4StoreNo = sp.GetOutput().GetData2("n4StoreNo", 0);

			return n4StoreNo;
		}

		public static StoreEntity GetInfo(string strUserID)
		{
			StoreGetInfoArguments arg = new StoreGetInfoArguments();
			arg.strUserID = strUserID;
			StoreGetInfo sp = new StoreGetInfo();
			sp.SetArguments(arg);
			StoreEntity info = sp.ExecuteNonQuery();
			return info;
		}

		public static StoreEntity GetInfo(int n4StoreNo)
		{
			StoreGetInfoArguments arg = new StoreGetInfoArguments();
			arg.n4StoreNo = n4StoreNo;
			StoreGetInfo sp = new StoreGetInfo();
			sp.SetArguments(arg);
			StoreEntity info = sp.ExecuteNonQuery();
			return info;
		}

		public static ListData<StoreEntity, OutputEntity> GetList(string IsActive, int PageNo, byte PageSize)
		{
			StoreGetListArguments arg = new StoreGetListArguments();
			arg.IsActive = IsActive;
			arg.PageNo = PageNo;
			arg.PageSize = PageSize;

			StoreGetList sp = new StoreGetList();
			sp.SetArguments(arg);
			sp.Execute();

			List<StoreEntity> list = sp.GetRecords();
			OutputEntity output = sp.GetOutput();
			return new ListData<StoreEntity, OutputEntity>(list, output);
		}

		public static ListData<StoreEntity, OutputEntity> GetSearch(string CityName, string StoreName, int PageNo, byte PageSize)
		{
			StoreGetSearchArguments arg = new StoreGetSearchArguments();

			if (CityName != string.Empty)
				arg.strCityName = CityName;
			if (StoreName != string.Empty)
				arg.strStoreName = StoreName;

			arg.PageNo = PageNo;
			arg.PageSize = PageSize;

			StoreGetSearch sp = new StoreGetSearch();
			sp.SetArguments(arg);
			sp.Execute();

			List<StoreEntity> list = sp.GetRecords();
			OutputEntity output = sp.GetOutput();
			return new ListData<StoreEntity, OutputEntity>(list, output);
		}

		public static ListData<NewStoreEntity, OutputEntity> GetListByNewStore(int PageNo, byte PageSize)
		{
			StoreGetListByNewStoreArguments arg = new StoreGetListByNewStoreArguments();
			arg.PageNo = PageNo;
			arg.PageSize = PageSize;

			StoreGetListByNewStore sp = new StoreGetListByNewStore();
			sp.SetArguments(arg);
			sp.Execute();


			List<NewStoreEntity> list = sp.GetRecords();
			OutputEntity output = sp.GetOutput();
			return new ListData<NewStoreEntity, OutputEntity>(list, output);
		}

		public static void Modify(int n4StoreNo, string IsActive, string strStoreName, string strCompanyNo, string strPhone, string strPost, string strAddress, string strCityName, string IsTakeout, string strTakeout
			, string IsParking, string strParking, string strStoreSize, string strOpenDate, string strOpenTime, string strPointX, string strPointY, string strDescription, string ManagerName)
		{
			StoreModifyArguments arg = new StoreModifyArguments();
			arg.n4StoreNo = n4StoreNo;
			if (IsActive != null && IsActive != string.Empty) arg.IsActive = IsActive;
			if (strStoreName != null && strStoreName != string.Empty) arg.strStoreName = strStoreName;
			if (strCompanyNo != null && strCompanyNo != string.Empty) arg.strCompanyNo = strCompanyNo;
			if (strPhone != null && strPhone != string.Empty) arg.strPhone = strPhone;
			if (strPost != null && strPost != string.Empty) arg.strPost = strPost;
			if (strAddress != null && strAddress != string.Empty) arg.strAddress = strAddress;
			if (strCityName != null && strCityName != string.Empty) arg.strCityName = strCityName;
			if (IsTakeout != null && IsTakeout != string.Empty) arg.IsTakeout = IsTakeout;
			if (strTakeout != null && strTakeout != string.Empty) arg.strTakeout = strTakeout;
			if (IsParking != null && IsParking != string.Empty) arg.IsParking = IsParking;
			if (strParking != null && strParking != string.Empty) arg.strParking = strParking;
			if (strStoreSize != null && strStoreSize != string.Empty) arg.strStoreSize = strStoreSize;
			if (strOpenDate != null && strOpenDate != string.Empty) arg.strOpenDate = strOpenDate;
			if (strOpenTime != null && strOpenTime != string.Empty) arg.strOpenTime = strOpenTime;
			if (strPointX != null && strPointX != string.Empty) arg.strPointX = strPointX;
			if (strPointY != null && strPointY != string.Empty) arg.strPointY = strPointY;
			if (strDescription != null && strDescription != string.Empty) arg.strDescription = strDescription;
			if (ManagerName != null && ManagerName != string.Empty) arg.strManagerName = ManagerName;

			StoreModify sp = new StoreModify();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void Remove(string strUserID)
		{
			StoreRemoveArguments arg = new StoreRemoveArguments();
			arg.strUserID = strUserID;

			StoreRemove sp = new StoreRemove();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void SetActive(string strUserID, string IsActive, string ManagerName)
		{
			StoreSetActiveArguments arg = new StoreSetActiveArguments();
			arg.strUserID = strUserID;
			arg.IsActive = IsActive;
			arg.strManagerName = ManagerName;

			StoreSetActive sp = new StoreSetActive();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void BestCreate(int n4StoreNo, string strManagerName)
		{
			StoreBestCreateArguments arg = new StoreBestCreateArguments();
			arg.n4StoreNo = n4StoreNo;
			arg.strManagerName = strManagerName;

			StoreBestCreate sp = new StoreBestCreate();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static ListData<StoreBestEntity, OutputEntity> BestGetList(int PageNo, byte PageSize)
		{
			StoreBestGetListArguments arg = new StoreBestGetListArguments();
			arg.PageNo = PageNo;
			arg.PageSize = PageSize;

			StoreBestGetList sp = new StoreBestGetList();
			sp.SetArguments(arg);
			sp.Execute();

			List<StoreBestEntity> list = sp.GetRecords();
			OutputEntity output = sp.GetOutput();

			return new ListData<StoreBestEntity, OutputEntity>(list, output);
		}

		public static StoreBestEntity BestGetInfo(int n4StoreNo)
		{
			StoreBestGetInfoArguments arg = new StoreBestGetInfoArguments();
			arg.n4StoreNo = n4StoreNo;

			StoreBestGetInfo sp = new StoreBestGetInfo();
			sp.SetArguments(arg);
			StoreBestEntity info = sp.ExecuteNonQuery();

			return info;
		}

		public static void BestRemove(int n4StoreNo)
		{
			StoreBestRemoveArguments arg = new StoreBestRemoveArguments();
			arg.n4StoreNo = n4StoreNo;

			StoreBestRemove sp = new StoreBestRemove();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void ImageCreate(int n4StoreNo, string strImageURL, string strManagerName)
		{
			StoreImageCreateArguments arg = new StoreImageCreateArguments();
			arg.n4StoreNo = n4StoreNo;
			arg.strImageURL = strImageURL;
			arg.strManagerName = strManagerName;
			StoreImageCreate sp = new StoreImageCreate();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void ImageRemove(int n4StoreNo, int? n4SeqNo)
		{
			StoreImageRemoveArguments arg = new StoreImageRemoveArguments();
			arg.n4StoreNo = n4StoreNo;
			if ( n4SeqNo.HasValue)
				arg.n4SeqNo = n4SeqNo.Value;

			StoreImageRemove sp = new StoreImageRemove();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static List<StoreImageEntity> ImageGetList(int n4StoreNo, byte PageSize)
		{
			StoreImageGetListArguments arg = new StoreImageGetListArguments();
			arg.n4StoreNo = n4StoreNo;
			arg.PageNo = 1;
			arg.PageSize = PageSize;
			StoreImageGetList sp = new StoreImageGetList();
			sp.SetArguments(arg);
			List<StoreImageEntity> list = sp.Execute();
			return list;
		}

		public static void MainCreate(int n4StoreNo, string strTitleImageURL, string strTitleOverImageURL, string strImageURL, string strManagerName)
		{
			StoreMainCreateArguments arg = new StoreMainCreateArguments();
			arg.n4StoreNo = n4StoreNo;
			arg.strTitleImageURL = strTitleImageURL;
			arg.strTitleOverImageURL = strTitleOverImageURL;
			arg.strImageURL = strImageURL;
			arg.strManagerName = strManagerName;
			StoreMainCreate sp = new StoreMainCreate();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void MainModify(int n4StoreNo, string strTitleImageURL, string strTitleOverImageURL, string strImageURL, string strManagerName)
		{
			StoreMainModifyArguments arg = new StoreMainModifyArguments();
			arg.n4StoreNo = n4StoreNo;
			arg.strTitleImageURL = strTitleImageURL;
			arg.strTitleOverImageURL = strTitleOverImageURL;
			arg.strImageURL = strImageURL;
			arg.strManagerName = strManagerName;
			StoreMainModify sp = new StoreMainModify();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void MainRemove(int n4StoreNo)
		{
			StoreMainRemoveArguments arg = new StoreMainRemoveArguments();
			arg.n4StoreNo = n4StoreNo;
			StoreMainRemove sp = new StoreMainRemove();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static List<StoreMainEntity> MainGetList(byte PageSize)
		{
			StoreMainGetListArguments arg = new StoreMainGetListArguments();
			arg.PageNo = 1;
			arg.PageSize = 10;
			StoreMainGetList sp = new StoreMainGetList();
			sp.SetArguments(arg);
			List<StoreMainEntity> list = sp.Execute();

			return list;
		}
	}
}
